package com.allenkerr.cloud.movie.controller;

import com.allenkerr.cloud.movie.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 小柯(Allen Kerr) on 17.6.13 14:59.
 */
@RestController
public class MovieController {

    @Autowired
    private RestTemplate restTemplate;

    @Value("${user.service.path}")
    private String userServicePath;
    //private String userServicePath = "http://microservice-provider-user";

    /**
     * 所有用户信息
     */
    @GetMapping("/movie/users")
    public List<User> findAllUsers() {
        return restTemplate.getForObject(userServicePath + "/users", new ArrayList<User>().getClass());
    }

    /**
     * 单个用户信息
     */
    @GetMapping("/movie/users/{id}")
    public User findUserById(@PathVariable Long id) {
        return restTemplate.getForObject(userServicePath + "/users/" + id, User.class);
    }

}
